﻿using System;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

using JSONObject = MyLibrary.Text.JSON.Utility.JSONObject;
using JSONArray = MyLibrary.Text.JSON.Utility.JSONArray;
using JSONTokener = MyLibrary.Text.JSON.Utility.JSONTokener;

namespace MyLibrary.Text.JSON.Serializer
{
    [Serializable]
    public class JSONSerializer : System.Runtime.Serialization.ISerializable
    {
        private static Dictionary<string, Type> _typeCache = new Dictionary<string, Type>();
        private static Dictionary<string, Type> _arrayTypeCache = new Dictionary<string, Type>();
        private static Dictionary<Type, IJSONSerializer> _serializerCache = new Dictionary<Type, IJSONSerializer>();

        /// <summary>
        /// 构造函数
        /// </summary>
        protected JSONSerializer(SerializationInfo renamed, StreamingContext context)
        {

        }

        private Type GetType(string type)
        {
            if (_typeCache.ContainsKey(type))
                return _typeCache[type];
            else
            {
                Type result = Type.GetType(type);
                _typeCache[type] = result;
                return result;
            }
        }

        private Type GetArrayType(string type)
        {
            if (_arrayTypeCache.ContainsKey(type))
                return _arrayTypeCache[type];
            else
            {
                Type elemType = GetType(type);
                Type result = (Array.CreateInstance(elemType, 0)).GetType();
                _arrayTypeCache[type] = result;
                return result;
            }
        }


    }
}
